package com.yu1996.search.service;

import com.yu1996.search.dao.ArticleDao;
import com.yu1996.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ArticleService {

    @Autowired
    private ArticleDao articleDao;

    /**
     * @param article 索引库的对象
     * @return void
     * @description 添加索引
     * @date 2019/10/15 18:53
     */
    public void save(Article article) {
        articleDao.save(article);
    }

    /**
     * @param keywords 搜索内容
     * @param page     分页
     * @param size     分页
     * @return org.springframework.data.domain.Page<com.yu1996.search.pojo.Article>
     * @description
     * @date 2019/10/15 18:58
     */
    public Page<Article> findTitlePage(String keywords, int page, int size) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return articleDao.findByTitleOrContentLike(keywords, keywords, pageable);
    }
}